<?php

/**
 * AVE.cms - Модуль Галерея.
 *
 * @package AVE.cms
 * @subpackage module_Gallery
 * @filesource
 */

/**
 * mySQL-запросы для установки, обновления и удаления модуля
 */

$module_sql_install = array();
$module_sql_deinstall = array();
$module_sql_update = array();

//Удаление модуля
$module_sql_deinstall[] = "DROP TABLE IF EXISTS CPPREFIX_module_gallery;";
$module_sql_deinstall[] = "DROP TABLE IF EXISTS CPPREFIX_module_gallery_images;";

//Установка модуля
$module_sql_install[] = "CREATE TABLE `CPPREFIX_module_gallery` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `gallery_title` varchar(255) NOT NULL,
  `gallery_description` text NOT NULL,
  `gallery_author_id` int(10) unsigned NOT NULL default '0',
  `gallery_created` int(10) unsigned NOT NULL default '0',
  `gallery_thumb_width` smallint(3) unsigned NOT NULL default '120',
  `gallery_thumb_height` smallint(3) unsigned NOT NULL default '120',
  `gallery_thumb_method` enum('c','r') NOT NULL default 'c',
  `gallery_image_on_line` tinyint(1) unsigned NOT NULL default '4',
  `gallery_image_on_page` tinyint(1) unsigned NOT NULL default '12',
  `gallery_watermark` varchar(255) NOT NULL,
  `gallery_folder` varchar(255) NOT NULL,
  `gallery_orderby` enum('datedesc','dateasc','titleasc','titledesc','position') NOT NULL default 'datedesc',
  `gallery_script` text NOT NULL,
  `gallery_image_template` text NOT NULL,
  `gallery_sepp_line` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 PACK_KEYS=0;";

$module_sql_install[] = "CREATE TABLE `CPPREFIX_module_gallery_images` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `gallery_id` int(10) unsigned NOT NULL default '0',
  `image_filename` varchar(255) NOT NULL,
  `image_author_id` int(10) unsigned NOT NULL default '0',
  `image_title` varchar(255) NOT NULL,
  `image_description` text NOT NULL,
  `image_file_ext` char(4) NOT NULL,
  `image_date` int(10) unsigned NOT NULL default '0',
  `image_position` smallint(3) unsigned NOT NULL default '1',
  `image_link` varchar(255) NOT NULL,
  `image_status` enum('1','0') NOT NULL DEFAULT '1',
  PRIMARY KEY  (`id`),
  KEY `image_position` (`image_position`),
  KEY `image_date` (`image_date`),
  KEY `gallery_id` (`gallery_id`),
  KEY `image_title` (`image_title`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 PACK_KEYS=0;";

// Обновление модуля
$module_sql_update[] = "
  UPDATE
    `CPPREFIX_module`
  SET
    ModuleAveTag = '" . $modul['ModuleAveTag'] . "',
    ModulePHPTag = '" . $modul['ModulePHPTag'] . "',
    ModuleVersion = '" . $modul['ModuleVersion'] . "'
  WHERE
    ModuleSysName = '" . $modul['ModuleSysName'] . "'
  LIMIT 1;
";

$module_sql_update[] = "
  RENAME TABLE
    `CPPREFIX_modul_gallery`
  TO
    `CPPREFIX_module_gallery`
";

$module_sql_update[] = "
  RENAME TABLE
    `CPPREFIX_modul_gallery_images`
  TO
    `CPPREFIX_module_gallery_images`
";

$module_sql_update[] = "
  ALTER TABLE `".PREFIX."_module_gallery_images`
  ADD
    `image_link`
  varchar(255) NOT NULL default '' AFTER
    `image_position`
";

$module_sql_update[] = "
  ALTER TABLE `".PREFIX."_module_gallery_images`
  ADD
    `image_status`
  enum('1','0') NOT NULL DEFAULT '1' AFTER
    `image_link`
";

?>